/*
 * @Author: duanguang
 * @Date: 2020-05-18 16:21:42
 * @LastEditTime: 2020-12-22 11:01:48
 * @LastEditors: duanguang
 * @Description: 
 * @FilePath: /legions-Luban/client/src/home/index.ts
 * @「扫去窗上的尘埃，才可以看到窗外的美景。」
 */
import '@babel/polyfill';
import create from 'legions';
import App from './containers/App';
/* import '../common/components/nprogress/index.css'; */
const app = create({ enableDevTools: false, router: true, history: null });
import ReactDOM from 'react-dom';
import { configure } from 'mobx';
import { getInjector } from 'brain-store';
import GlobalStateStore from './stores/globalStateStore';
import { resource } from 'legions/store';
configure({ isolateGlobalState: true });
app.start(App, '#react-luban');
function render() {
  app.start(App, '#react-luban');
}
const userEventResource = resource('master/resource/user');
export async function bootstrap() {}

export async function mount(props) {
  const stores = getInjector();
  const globalStateStore: GlobalStateStore = stores.getState(GlobalStateStore,true);
  if (globalStateStore) {
    globalStateStore.syncUpdateGlobalState(props);
    globalStateStore.onGlobalStateChange((value,prev,event) => {
      console.log(`[onGlobalStateChange - ${props.name}]:`,value,prev,event)
      if (value.user) {
        globalStateStore.userInfo = value.user;
      }
    },{
        fireImmediately: true,
        eventScopes:[userEventResource],
    })
  }
  render();
}

export async function unmount() {
  ReactDOM.unmountComponentAtNode(document.querySelector('#react-luban'));
}
/* if (!global['_babelPolyfill']) {
    // 为了解决重复引入的问题
    require('babel-polyfill');
} */
// @ts-ignore
if (module.hot && process.env.NODE_ENV === 'dev') {
  // @ts-ignore
  module.hot.accept();
}
